<template>
	<view class="wrap"><baseForm :column.sync="column" @submitFun="submitFun"></baseForm></view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import login from '@/libs/login.js'
import formMixins from '@/libs/formMixins.js';
export default {
	mixins: [formMixins],
	data() {
		return {
			user:"",
			column: [
				{
					label: '报销名称', //输入框title
					name: 'reimburseName', //传值类型
					type: 'normalInput', //输入框类型
					disabled: false, //是否禁用
					required: true, //是否必须填写
					value: '' //输入框的值
				},
				{
					label: '报销金额',
					name: 'reimburseAmount',
					type: 'normalInput',
					required: true,
					disabled: false,
					value: ''
				},
				{
					label: '备注',
					name: 'remark',
					type: 'normalInput',
					disabled: false,
					required: false,
					value: ''
				},

				{
					label: '附件(发票收据)',
					type: 'upload',
					url: '/stu/common/uploadFile',
					docFileId: '',
					docFileUrl: '',
					docFileName: '',
					attachmentVoListStr: '',
					limitSize: 9,
					disabled: false
				}
			]
		};
	},
	async onLoad(){
		this.user = await login.getStorage('user');
	},
	methods: {
		async submitFun() {
			let params = {
				applicantJobNumber: this.user.number, //申请人教职工号
				applicantName: this.user.name, //申请人姓名
				attachmentVoListStr: this.column[3].attachmentVoListStr, //附件列表
				reimburseAmount: this.column[1].value, //报销金额
				reimburseName: this.column[0].value, //报销名称
				remark: this.column[2].value,  //备注
			};
			let rules = [
				{
					key: 'reimburseName',
					checkFunc(value) {
						if (!value)	return false;
						return true;
					},
					errMsg: '请输入报销名称'
				},
				{
					key: 'reimburseAmount',
					checkFunc(value) {
						let reg = /^[0-9]+.?[0-9]*$/;
						return reg.test(value);
					},
					errMsg: '请输入正确的报销金额'
				}
			]
			let checkRes = this.checkFormIsPassRules(params, rules);
			if (!checkRes.isPass) {
				this.showToast(checkRes.errMsg);
				return;
			}
			let resp = await this.$http.post({
				url: '/oa/reimburseApply/save',
				data: params
			})
			this.showToast('提交成功',()=> {uni.navigateBack()});
		}
	},
	components: {
		baseForm
	}
};
</script>

<style lang="scss" scoped>
page {
	min-height: 100%;
}
.wrap {
	height: 100%;
}
</style>
